package com.example.task;

import com.example.service.CouponService;
import com.example.service.UserCouponService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
public class CouponStatusUpdateTask {

    @Resource
    private CouponService couponService;

    @Resource
    private UserCouponService userCouponService;


    @Scheduled(cron = "0 0 * * * ?") // 每隔1小时执行一次
    public void updateCouponStatus() {
        log.info("执行优惠券状态更新定时任务");
        LocalDateTime now = LocalDateTime.now();
        couponService.updateStatusToPending(now);      // 更新优惠券状态为待开始
        couponService.updateStatusToStart(now);      // 更新优惠券状态为进行中
        couponService.updateStatusToEnded(now);        // 更新优惠券状态为已结束
        couponService.updateStatusToExpired(now);      // 更新优惠券状态为已失效
    }
}